﻿using SSPivot.AspNetCore.Abstractions.Data;
using SSPivot.Common.Interface;
using System.Data;

namespace SSPivot.Admin.Host.Core.Migrators
{
    public class DbMigrationService : ITransientDependency
    {
        private readonly IDataSeeder _dataSeeder;
        private readonly IDbSchemaMigrator _dbSchemaMigrator;

        public DbMigrationService(
            IDataSeeder dataSeeder,
            IDbSchemaMigrator dbSchemaMigrator
            )
        {
            _dataSeeder = dataSeeder;
            _dbSchemaMigrator = dbSchemaMigrator;
        }

        public async Task MigrateAsync()
        {
            await MigrateDatabaseSchemaAsync();
            await SeedDataAsync();
        }

        private async Task SeedDataAsync()
        {
            await _dataSeeder.SeedAsync();
        }

        public async Task MigrateDatabaseSchemaAsync()
        {
            await _dbSchemaMigrator.MigrateAsync();
        }
    }
}
